package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.EmployExamMapper;
import com.ruoyi.system.domain.EmployExam;
import com.ruoyi.system.service.IEmployExamService;

/**
 * 聘期考核Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-14
 */
@Service
public class EmployExamServiceImpl implements IEmployExamService 
{
    @Autowired
    private EmployExamMapper employExamMapper;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    /**
     * 查询聘期考核
     * 
     * @param id 聘期考核主键
     * @return 聘期考核
     */
    @Override
    public EmployExam selectEmployExamById(Long id)
    {
        return employExamMapper.selectEmployExamById(id);
    }

    /**
     * 查询聘期考核列表
     * 
     * @param employExam 聘期考核
     * @return 聘期考核
     */
    @Override
    public List<EmployExam> selectEmployExamList(EmployExam employExam)
    {



        if(SecurityUtils.hasRole("admin") || SecurityUtils.hasRole("school")){
            EmployExam exam = new EmployExam();
            return employExamMapper.selectEmployExamList(exam);
        }
        else if (SecurityUtils.hasRole("director")){
            //如果是部门领导
            //获取部门ID
            Long deptId = SecurityUtils.getDeptId();

            employExam.setDeptId(deptId);
            employExam.setProgress("0");

            return employExamMapper.selectEmployExamList(employExam);
        }else if(SecurityUtils.hasRole("common")){
            employExam.setUserId(SecurityUtils.getUserId());
            return employExamMapper.selectEmployExamList(employExam);
        }

        return employExamMapper.selectEmployExamList(employExam);




    }

    /**
     * 新增聘期考核
     * 
     * @param employExam 聘期考核
     * @return 结果
     */
    @Override
    public int insertEmployExam(EmployExam employExam)
    {
        employExam.setCreateTime(DateUtils.getNowDate());
        employExam.setUserId(SecurityUtils.getUserId());
        employExam.setDeptId(SecurityUtils.getDeptId());
        employExam.setUserName(SecurityUtils.getUsername());
        employExam.setProgress("0");
        return employExamMapper.insertEmployExam(employExam);
    }

    /**
     * 修改聘期考核
     * 
     * @param employExam 聘期考核
     * @return 结果
     */
    @Override
    public int updateEmployExam(EmployExam employExam)
    {
        employExam.setUpdateTime(DateUtils.getNowDate());
        //更新如果是部门操作
        EmployExam employExam1 = employExamMapper.selectEmployExamById(employExam.getId());
        //判断所处过程
        if(employExam1.getProgress().equals("0")){
            employExam.setProgress("1");
        }else if(employExam1.getProgress().equals("1")){
            employExam.setProgress("2");
        }
        return employExamMapper.updateEmployExam(employExam);
    }

    /**
     * 批量删除聘期考核
     * 
     * @param ids 需要删除的聘期考核主键
     * @return 结果
     */
    @Override
    public int deleteEmployExamByIds(Long[] ids)
    {
        return employExamMapper.deleteEmployExamByIds(ids);
    }

    /**
     * 删除聘期考核信息
     * 
     * @param id 聘期考核主键
     * @return 结果
     */
    @Override
    public int deleteEmployExamById(Long id)
    {
        return employExamMapper.deleteEmployExamById(id);
    }
}
